package com.niuwa.p2p.action.claimtransfer;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

import com.niuwa.p2p.action.JsonAction;
import com.niuwa.p2p.entity.business.CustClaim;
import com.niuwa.p2p.entity.claimtransfer.TransferRecord;
import com.niuwa.p2p.service.business.ICustClaimService;
import com.niuwa.p2p.service.business.IDirectProductService;
import com.niuwa.p2p.service.claimtransfer.ITransferApplyService;
import com.niuwa.p2p.service.claimtransfer.ITransferRecordService;
import com.niuwa.p2p.vo.business.ClaimDetailVo;
import com.opensymphony.xwork2.ActionContext;

public class ClaimAction extends JsonAction {
	
	@Autowired
	private IDirectProductService directProdService;
	
	@Autowired
	private ICustClaimService claimService;
	
	@Autowired
	private ITransferRecordService transferRecordService;
	
	@Autowired
	private ITransferApplyService transferApplyService;
	
	/** 债权信息 */
	List<CustClaim> claims;
	
	/** 转让记录 */
	List<TransferRecord> transferRecords;
	
	private ClaimDetailVo claimDetailVo;
	
	private CustClaim custClaim;
	
	/** 产品编号 */
	private String productCode;
	
	/** 债权编号 */
	private String creditNo;
	
	/** 自转债权流水号 */
	private String serialNo;
	
	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	public CustClaim getCustClaim() {
		return custClaim;
	}

	public void setCustClaim(CustClaim custClaim) {
		this.custClaim = custClaim;
	}

	public String getCreditNo() {
		return creditNo;
	}

	public void setCreditNo(String creditNo) {
		this.creditNo = creditNo;
	}

	public List<TransferRecord> getTransferRecords() {
		return transferRecords;
	}

	public void setTransferRecords(List<TransferRecord> transferRecords) {
		this.transferRecords = transferRecords;
	}

	public List<CustClaim> getClaims() {
		return claims;
	}

	public void setClaims(List<CustClaim> claims) {
		this.claims = claims;
	}

	public ClaimDetailVo getClaimDetailVo() {
		return claimDetailVo;
	}

	public void setClaimDetailVo(ClaimDetailVo claimDetailVo) {
		this.claimDetailVo = claimDetailVo;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	/**
	 * 自转债权/债权信息详情页
	 * @return
	 */
	@Action("gotoClaimDetails")
	public String gotoClaimDetails() throws Exception{
		//productCode = "CPZT00000000000000000021";
		
		ActionContext context = ActionContext.getContext();
				
		//获取产品相关信息
		claimDetailVo = directProdService.getProductRelativeInfo(productCode);
		context.put("claimDetailVo", claimDetailVo);
		//债权信息
		claims = claimService.selectCustClaimByProdCode(productCode);
		context.put("claims", claims);
		//转让记录
		transferRecords = transferRecordService.selectTransferRecordByProdCode(productCode);
		context.put("transferRecords", transferRecords);
		
		return "claimDetails";
	}
	
	/**
	 * 自转债权通过
	 * @return
	 * @throws Exception
	 */
	/*@Action("passClaim")
	public String passClaim(){
		//当前登录者ID
		Long userId = SessionUtil.getSessionUser().getId();
		try {
			if(!StringUtil.isEmpty(serialNo)){
				transferApplyService.addPassClaim(userId, serialNo);
				//成功
				this.setDefaultSuccessResult();
			}
		} catch (Exception e) {
			this.setDefaultFailedResult();
			return NONE;
		}
		return NONE;
	}*/
	
	/**
	 * 自转债权信息详情页
	 * @return
	 */
	/*@Action("gotoRotationClaimDetails")
	public String gotoRotationClaimDetails() throws Exception{
		creditNo = "123";
		
		ActionContext context = ActionContext.getContext();
		//债权信息
		custClaim = claimService.selectCustClaimByCreditNo(creditNo);
		claims.add(custClaim);
		context.put("claims", claims);
		String prodNo = custClaim.getProdCode();
		if(!StringUtil.isEmpty(prodNo)){
			//获取产品相关信息
			claimDetailVo = directProdService.getProductRelativeInfo(prodNo);
			context.put("claimDetailVo", claimDetailVo);
		}
		//转让记录
		transferRecords = transferRecordService.selectTransferRecordByProdCode(prodNo);
		context.put("transferRecords", transferRecords);
		
		return "claimDetails";
	}*/
	
	
}
